package com.yygo.model;

import com.yygo.model.enums.MaterialStatus;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tiansha on 2015/11/20.
 */
@Entity
@Table(name = "material_audit")
public class MaterialAudit {

    private Long id;

    private LoanRequest loanRequest;
    private List<Material> materialList = new ArrayList();
    private boolean started=false;
    private boolean allSent;
    private boolean allReceived;
    private boolean loanComplete;

    private User receiver;
    private User auditor;

    private MaterialStatus materialStatus = MaterialStatus.Receiving;

    private List<Feedback> feedbacks = new ArrayList<>();

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @OneToMany(mappedBy = "materialAudit", cascade= CascadeType.ALL, fetch = FetchType.LAZY)
    public List<Material> getMaterialList() {
        return materialList;
    }

    public void setMaterialList(List<Material> materialList) {
        this.materialList = materialList;
    }
    @Column(name="started")
    public boolean isStarted() {
        return started;
    }

    public void setStarted(boolean started) {
        this.started = started;
    }
    @Column(name="all_sent")
    public boolean isAllSent() {
        return allSent;
    }

    public void setAllSent(boolean allSent) {
        this.allSent = allSent;
    }

    @Column(name="all_received")
    public boolean isAllReceived() {
        return allReceived;
    }

    public void setAllReceived(boolean allReceived) {
        this.allReceived = allReceived;
    }

    @Column(name="loan_complete")
    public boolean isLoanComplete() {
        return loanComplete;
    }

    public void setLoanComplete(boolean loanComplete) {
        this.loanComplete = loanComplete;
    }

    @OneToOne()
    @JoinColumn(name="req_id")
    public LoanRequest getLoanRequest() {
        return loanRequest;
    }

    public void setLoanRequest(LoanRequest loanRequest) {
        this.loanRequest = loanRequest;
    }

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="receiver_user_id")
    public User getReceiver() {
        return receiver;
    }

    public void setReceiver(User receiver) {
        this.receiver = receiver;
    }

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="auditor_user_id")
    public User getAuditor() {
        return auditor;
    }

    public void setAuditor(User auditor) {
        this.auditor = auditor;
    }

    @OneToMany(mappedBy = "loanRequest", cascade=CascadeType.ALL)
    public List<Feedback> getFeedbacks() {
        return feedbacks;
    }

    public void setFeedbacks(List<Feedback> feedbacks) {
        this.feedbacks = feedbacks;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "material_status", length = 20)
    public MaterialStatus getMaterialStatus() {
        return materialStatus;
    }

    public void setMaterialStatus(MaterialStatus materialStatus) {
        this.materialStatus = materialStatus;
    }
}
